package groups;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Locale;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Temporal;

/**
 * A date for lectures or exercise groups
 * @author Thorsten Ludwig
 */

@Entity
public class MeetingDate implements Serializable {

    /**
     * 
     */
    
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Calendar startTime;
    /**
     * 
     */
    private int duration;
    @Id
    @GeneratedValue
    private Long id;



    /**
     * create a new date
     * @param hour starting time, hours
     * @param minute starting time, minutes
     * @param day day in the week when it takes place
     */
    public MeetingDate (int day_of_week, int hour, int minutes, int duration) {
        this.startTime = Calendar.getInstance();
        this.startTime.set(Calendar.DAY_OF_WEEK, day_of_week);
        this.startTime.set(Calendar.HOUR_OF_DAY, hour);
        this.startTime.set(Calendar.MINUTE, minutes);
        
        this.duration = duration;
        
    }
    
    public MeetingDate() {
        this.startTime = Calendar.getInstance();        
    }
    
    public void setDay(int day_of_week) {
        this.startTime.set(Calendar.DAY_OF_WEEK, day_of_week);
    }
    
    public int getDay() {
        return this.startTime.get(Calendar.DAY_OF_WEEK);
    }
    
    public void setHour(int hour) {
        this.startTime.set(Calendar.HOUR_OF_DAY, hour);
    }
    
    public int getHour() {
        return this.startTime.get(Calendar.HOUR_OF_DAY);
    }
    
    public void setMinute(int minute) {
        this.startTime.set(Calendar.MINUTE, minute); 
    }
    
    public int getMinute() {
        return this.startTime.get(Calendar.MINUTE);
    }
    
    
    
    @Override
    public String toString() {
        String day = this.startTime.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.GERMAN);
        String hour = Integer.toString(this.startTime.get(Calendar.HOUR_OF_DAY));
        if (hour.length() == 1)
            hour = "0" + hour;
        String minutes = Integer.toString(this.startTime.get(Calendar.MINUTE));
        if (minutes.length() == 1) 
            minutes = "0" + minutes;
        return day + " " + hour + ":" + minutes;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
}
